# import cv2
# vc_path = "videos/001.mp4"
# vc = cv2.VideoCapture(vc_path)
# fps = vc.get(cv2.CAP_PROP_FPS)
# size = (vc.get(cv2.CAP_PROP_FRAME_WIDTH),
#         vc.get(cv2.CAP_PROP_FRAME_HEIGHT))
# print(f"FPS(帧速率)：{fps}")
# print(f"SIZE(大小)：{size}")
#
# success, frame = vc.read()
# while success:
#     cv2.imshow(vc_path, frame)
#     success, frame = vc.read()
#     key = cv2.waitKey(50)
#     if key == 27:
#         break
# vc.release()

# import cv2
# # 视频路径
# vc_path = "videos/004.mp4"
# # 获取视频对象，便于后续操作
# vc = cv2.VideoCapture(vc_path)
# # vc.get()获取帧速率
# fps = vc.get(cv2.CAP_PROP_FPS)
# # 获取WH，组成元组
# size = (vc.get(cv2.CAP_PROP_FRAME_WIDTH),
#         vc.get(cv2.CAP_PROP_FRAME_HEIGHT))
# print(f"FPS(帧速率)：{fps}")
# print(f"SIZE(大小)：{size}")
#
# # success是bool类型，frame是该帧动画
# success, frame = vc.read()
# while success:
#     cv2.imshow(vc_path, frame)
#     success, frame = vc.read()
#     key = cv2.waitKey(50)
#     if key == 27:
#         break
# vc.release()

# import cv2
# # 视频路径
# vc_path = "videos/004.mp4"
# # 获取视频对象，便于后续操作
# vc = cv2.VideoCapture(vc_path)
# # vc.get()获取帧速率
# fps = vc.get(cv2.CAP_PROP_FPS)
# # 获取WH，组成元组
# size = (int(vc.get(cv2.CAP_PROP_FRAME_WIDTH)),
#         int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT)))
# print(f"FPS(帧速率)：{fps}")
# print(f"SIZE(大小)：{size}")
#
# vw = cv2.VideoWriter("reserve_004.avi",
#                      cv2.VideoWriter_fourcc(*'XVID'),
#                      fps,
#                      size) # 必须是int类型
#
# # success是bool类型，frame是该帧动画
# success, frame = vc.read()
# while success:
#     vw.write(frame)
#     cv2.imshow(vc_path, frame)
#     key = cv2.waitKey(50)
#     if key == 27:
#         break
#     success, frame = vc.read()
# vc.release()

# Default parameter
import cv2
# 获取摄像头对象，便于后续操作
vc = cv2.VideoCapture(0)
# vc.get()获取帧速率
fps = 30
# 获取WH，组成元组
size = (int(vc.get(cv2.CAP_PROP_FRAME_WIDTH)),
        int(vc.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print(f"FPS(帧速率)：{fps}")
print(f"SIZE(大小)：{size}")

vw = cv2.VideoWriter("test.avi",
                     cv2.VideoWriter_fourcc(*'XVID'),
                     fps,
                     size) # 必须是int类型

# success是bool类型，frame是该帧动画
success, frame = vc.read()
while success:
    vw.write(frame)
    cv2.imshow("0", frame)
    key = cv2.waitKey(50)
    if key == 27:
        break
    success, frame = vc.read()
vc.release()